package main

import (
	sorter "alorithm-go/sort"
	"fmt"
	"time"
)

const (
	length = 5
	maxNum = 100
)

func main() {
	var sort sorter.ISorter

	//sort = &sorter.InsertSort{}
	//sortPrint(sort)
	//performanceTest(sort)
	////
	//sort = &sorter.BubbleSort{}
	//sortPrint(sort)
	//performanceTest(sort)
	////
	//sort = &sorter.SelectSort{}
	//sortPrint(sort)
	//performanceTest(sort)
	//
	//sort = &sorter.ShellSort{}
	//sortPrint(sort)
	//performanceTest(sort)
	//
	//sort = &sorter.MergeSort{}
	//sortPrint(sort)
	//performanceTest(sort)

	//sort1 := &sorter.MergeSort{}
	//sort1.GenArray(length, maxNum)
	//sort1.MergeSort()
	//sort1.PrintArray()
	//println(sort1.IsSorted())

	//sort = &sorter.QuickSort{}
	//sortPrint(sort)
	//performanceTest(sort)

	//sort = &sorter.ThreeWayQuickSort{}
	//sortPrint(sort)
	//performanceTest(sort)

	//sort = &sorter.HeapSort{}
	//sortPrint(sort)
	//performanceTest(sort)

	//sort = &sorter.Counter{}
	//sortPrint(sort)
	//performanceTest(sort)

	sort = &sorter.BucketSort{}
	sortPrint(sort)

}

func sortPrint(sort sorter.ISorter) {
	name := sort.Name()
	sort.GenArray(length, maxNum)
	//sort.GenStableArray()
	fmt.Println("使用[" + name + "]排序前：")
	sort.PrintArray()
	sort.Sort()
	fmt.Println("使用[" + name + "]排序后：")
	sort.PrintArray()

	fmt.Println("是否有序：", sort.IsSorted())
}

func performanceTest(sort sorter.ISorter) {
	name := sort.Name()

	start := time.Now()

	sort.Sort()

	time.Sleep(1 * time.Second)
	second := time.Since(start)

	fmt.Printf("使用%v排序消耗时间: %v \n", name, second)
}
